package com.webauto.data_driver;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.LinkedHashMap;
import java.util.Map;

import org.yaml.snakeyaml.Yaml;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.webauto.log.Log;
import com.webauto.pojo.Element;
import com.webauto.util.Constant;

/**
 * PS:yaml数据工具类
 * @author lkk
 *
 */
public class YamlUtil {
	//yaml所有数据集合
	public static Map<String,Map> pages;
	
	//初始化yaml集合
	static {
		pages = loadYamlData(Constant.YAML_PATH);
	}

	/**
	 * PS:初始化yaml所有数据
	 * @return
	 */
	public static Map<String,Map> loadYamlData(String yamlPath) {
		File file = new File(yamlPath);
		Yaml yaml = new Yaml();
		Map<String,Map> map = null;
		try {
			//将yaml数据加载到map中
			map = yaml.loadAs(new FileInputStream(file), Map.class);
		} catch (FileNotFoundException e) {
			Log.error("+++yaml文件解析异常,文件路径:"+yamlPath+"+++");
		}
		return map;
	}
}
